package com.zhanqiao.Dao;


import com.zhanqiao.Utils.GetDataSourceUtil;
import com.zhanqiao.domain.MessageBean;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import javax.sql.DataSource;
import java.sql.SQLException;

import java.util.List;


public class MessageDao implements MassageDao{
    @Override
    public int insertMessage(MessageBean messageBean) {

        return 0;
    }

    @Override
    public int deleteMessage(int articleId) {
        return 0;
    }

    @Override
    public List<MessageBean>  selectAll(String page,String limit) throws SQLException {
        int p=Integer.valueOf(page);
        int l=Integer.valueOf(limit);
        DataSource dataSource=GetDataSourceUtil.getDataSource();
        QueryRunner queryRunner=new QueryRunner(dataSource);
        Object []pars={(p-1)*l,l};
        List<MessageBean> Messages = queryRunner.query("SELECT massage.*,user.uname FROM massage,user where massage.uid=user.uid GROUP BY mid limit ?,?",pars, new BeanListHandler<>(MessageBean.class));
       System.out.println(Messages);
        return  Messages;

    }
}
